<?php
namespace app\commentConf\controller;
use app\common\Base;
use app\common\Compent;
use app\common\Emodel;
use think\Db;

class WeekConf extends Base {
	
	public function index() {
		return $this->fetch();
	}

	public function pageQuery() {
		if(request()->isPost()){
			$page = input('page');
			$rows = input('rows');
			$result = Db::table("功能模块")
			->page($page, $rows)->order("父级ID,顺序")->select();
			$count = Db::table("功能模块")->count();
			$data = selectResult($result);
			$list = [];
	        foreach ($data as $key => $obj) {
	            $obj["身份"]  = getPositionName($obj["身份IDS"]);
	            $list[$key] = $obj;
	        }
			$grid['rows'] = $list;
			$grid['total'] = $count;
			return $grid;
		}
	}

	public function addUpdate() {
		$all = request()->param();
		try {
			if(array_key_exists("ID", $all)) {
				update('功能模块', $all);
			} else {
				insert('功能模块', $all);
			}
			return "000";
		} catch (Exception $e) {
			echo $e->getMessage();
		}
		return "999";
	}

	public function del() {
		$delIds = input("delIds");
		try {
			Db::name('功能模块')->where('ID','in',explode(",", $delIds))->delete();
			return "000";
		} catch (Exception $e) {
			echo $e->getMessage();
		}
		return "999";
	}

	public function parentMenu() {
		$where["父级ID"] = 0; 
		$result = Db::table("功能模块")
				->where($where)
				->order("顺序")
				->select();
		return selectResult($result);
	}

}
